const jwt = require('jwt-simple')

const secret = 'iljsoiu.19283497ksdf12348,12341289jas.akdflj!asdofjoi9ADFKLkasndf'

module.exports = {
  // 生成 token
  generateToken(payload) {
    const _payload = { ...payload }
    _payload.exp = Math.floor(Date.now() / 1000) + 7 * 24 * 60 * 60
    return jwt.encode(_payload, secret)
  },
  // 验证 token
  verify(token) {
    return jwt.decode(token, secret)
  }
}